<template>
  <div class="m-view-verifySoleList m-window">
    <div class="m-condition">
      <el-form :model="searchForm">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="工厂代码：" label-width="88px">
              <el-input
                v-model="searchForm.factory"
                placeholder="输入工厂代码"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="零件类型：" label-width="88px">
              <el-input
                v-model="searchForm.partName"
                placeholder="输入零件类型"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="物料描述（材质）：" label-width="140px">
              <el-input
                v-model="searchForm.matDescription"
                placeholder="输入物料描述"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="创建日期：" label-width="88px">
              <el-date-picker
                v-model="searchForm.createDate"
                type="date"
                placeholder="输入日期"
                value-format="yyyy-MM-dd"
                :editable="false"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="申购单号：" label-width="88px">
              <el-input
                v-model="searchForm.purchaseNum"
                placeholder="输入单号"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="模具编号：" label-width="88px">
              <el-input
                v-model="searchForm.mouldNum"
                placeholder="请输入模具编号"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="2" class="m-floatright" v-if="btnStatus.toPurchase">
            <el-button type="primary" @click="purchaseApplay"
              >转采购申请</el-button
            >
          </el-col>

          <el-col :span="2" class="m-floatright" v-if="btnStatus.query">
            <el-button type="primary" @click="getPurchaseRequest"
              >查询</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="m-agTable m-bottom m-applySoleListTable">
      <ag-grid-vue
        class="m-agTableContent ag-theme-balham m-agCenter"
        :gridOptions="gridOptions"
        :columnDefs="columnDefs"
        :rowData="rowData"
        v-loading="loading"
        @cellFocused="dialogRowFocus"
        @cellClicked="handleClickCell"
      ></ag-grid-vue>
    </div>
    <div class="m-page">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        @prev-click="handlePrevClick"
        @next-click="handleNextClick"
        :current-page="searchForm.current"
        :page-sizes="[30, 50, 100, 150, 200]"
        :page-size="searchForm.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="searchForm.total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import gridOptions from "lesso-common/public/gridOptions";
import _Api from "@/api";
import authorize from "@/public/authorize";
import Vue from "vue";
import constant from "@/public/constant";

// 采购申请类型
const purchaseRequestTypeInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入类型"
                v-model="purchaseRequestTypeChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      purchaseRequestTypeChildren: "NB",
    };
  },
  created() {
    // this.purchaseRequestTypeChildren = this.params.data.purchaseRequestType;

      if(this.params.data.purchaseRequestType.length==0){
      this.params.data.purchaseRequestType="NB";
       this.purchaseRequestTypeChildren = this.params.data.purchaseRequestType;
    }else{
      this.purchaseRequestTypeChildren = this.params.data.purchaseRequestType;
    }
  },

  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.purchaseRequestType = this.purchaseRequestTypeChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 科目分配类别
const accountAssignmentCategoryInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入类别"
                v-model="accountAssignmentCategoryChildren" 
                @change="inputChange()"
                
                >
            </el-input>`,
  data() {
    return {
      accountAssignmentCategoryChildren: "",
    };
  },
  created() {
    this.accountAssignmentCategoryChildren = this.params.data.accountAssignmentCategory;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.accountAssignmentCategory = this.accountAssignmentCategoryChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 单位
const unitInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入单位"
                v-model="unitChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      unitChildren: "KG",
    };
  },
  created() {
    // this.unitChildren = this.params.data.unit;
      if(this.params.data.unit.length==0){
      this.params.data.unit="KG";
       this.unitChildren = this.params.data.unit;
    }else{
      this.unitChildren = this.params.data.unit;
    }
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.unit = this.unitChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 评估价格
const appraisalPriceInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入评估价格"
                v-model="appraisalPriceChildren" 
                @change="inputChange()"
                @blur="inputChange()"
                >
            </el-input>`,
  data() {
    return {
      appraisalPriceChildren: "",
    };
  },
  created() {
    if(this.params.data.appraisalPrice==false){
      this.params.data.appraisalPrice="";
       this.appraisalPriceChildren = this.params.data.appraisalPrice;
    }else{
      this.appraisalPriceChildren = this.params.data.appraisalPrice;
    }
    // this.appraisalPriceChildren = this.params.data.appraisalPrice;
  },
  methods: {
    // 输入变化
    inputChange() {
      
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.appraisalPrice = this.appraisalPriceChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
      
    },
  },
});
// 价格单位
const priceUnitInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入价格单位"
                v-model="priceUnitChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      priceUnitChildren: "",
    };
  },
  created() {
    this.priceUnitChildren = this.params.data.priceUnit;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.priceUnit = this.priceUnitChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 交货日期
const deliveryDateInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入交货日期"
                v-model="deliveryDateChildren" 
                @change="inputChange()"
                @blur="inputChange()"
                >
            </el-input>`,
  data() {
    return {
      deliveryDateChildren: "",
    };
  },
  created() {
    this.deliveryDateChildren = this.params.data.deliveryDate;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      if (this.deliveryDateChildren != null) {
        let isTrue = that.strDateTime(this.deliveryDateChildren);
        if (!isTrue) {
          this.$alert("输入时间格式不对！", {
            showClose: false,
            confirmButton: "确定",
            customClass: "alertFailure",
          });
        } else {
          focusRowData.deliveryDate = this.deliveryDateChildren;
          that.gridOptions.api.updateRowData({
            update: [focusRowData],
          });
        }
      }
    },
  },
});
// 物料组
const materialGroupInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入物料组"
                v-model="materialGroupChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      materialGroupChildren: "",
    };
  },
  created() {
    this.materialGroupChildren = this.params.data.materialGroup;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.materialGroup = this.materialGroupChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 库存地点
const stockLocationInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入库存地点"
                v-model="stockLocationChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      stockLocationChildren: "",
    };
  },
  created() {
    this.stockLocationChildren = this.params.data.stockLocation;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.stockLocation = this.stockLocationChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 采购组
const purchaseGroupInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入采购组"
                v-model="purchaseGroupChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      purchaseGroupChildren: "",
    };
  },
  created() {
    this.purchaseGroupChildren = this.params.data.purchaseGroup;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.purchaseGroup = this.purchaseGroupChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 申请者
const applicantInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入申请者"
                v-model="applicantChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      applicantChildren: "",
    };
  },
  created() {
    this.applicantChildren = this.params.data.applicant;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.applicant = this.applicantChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 成本中心
const costCentreInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入成本中心"
                v-model="costCentreChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      costCentreChildren: "",
    };
  },
  created() {
    this.costCentreChildren = this.params.data.costCentre;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.costCentre = this.costCentreChildren;
      if (focusRowData.costCentre) {
        focusRowData.accountAssignmentCategory = "K";
      }
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 项目文本
const itemTextInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入项目文本"
                v-model="itemTextChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      itemTextChildren: "",
    };
  },
  created() {
    this.itemTextChildren = this.params.data.itemText;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.itemText = this.itemTextChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 批次
const batchInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入批次"
                v-model="batchChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      batchChildren: "",
    };
  },
  created() {
    this.batchChildren = this.params.data.batch;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.batch = this.batchChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 需求跟踪号
const requirementTrackNumInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入批次"
                v-model="requirementTrackNumChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      requirementTrackNumChildren: "",
    };
  },
  created() {
    this.requirementTrackNumChildren = this.params.data.requirementTrackNum;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.requirementTrackNum = this.requirementTrackNumChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 项目类别
const projectTypeInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入项目类别"
                v-model="projectTypeChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      projectTypeChildren: "",
    };
  },
  created() {
    this.projectTypeChildren = this.params.data.projectType;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.projectType = this.projectTypeChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 采购组织
const purchaseOrgInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入采购组织"
                v-model="purchaseOrgChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      purchaseOrgChildren: "",
    };
  },
  created() {
    this.purchaseOrgChildren = this.params.data.purchaseOrg;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.purchaseOrg = this.purchaseOrgChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});
// 供货工厂
const supplyFactoryInput = Vue.extend({
  template: `<el-input
                class="inputStyle"
                placeholder="请输入供货工厂"
                v-model="supplyFactoryChildren" 
                @change="inputChange()">
            </el-input>`,
  data() {
    return {
      supplyFactoryChildren: "",
    };
  },
  created() {
    this.supplyFactoryChildren = this.params.data.supplyFactory;
  },
  methods: {
    // 输入变化
    inputChange() {
      let that = this.params.context.componentParent;
      let focusRowData = that.rowData[that.dialogSelectRowIndex];
      focusRowData.supplyFactory = this.supplyFactoryChildren;
      that.gridOptions.api.updateRowData({
        update: [focusRowData],
      });
    },
  },
});

export default {
  data() {
    return {
      searchForm: {
        factory: "", //工厂代码
        partName: "", //零件类型
        matDescription: "", //材质
        createDate: "", //日期
        purchaseNum: "", //单号
        mouldNum: "", //模具编号

        size: 30,
        current: 1,
        total: 0,
      },
      // 权限控制
      // todo : 对接权限后需要把btnStatus全部置为false
      pageCode: "verifySoleList",
      btnStatus: {
        query: false, //查询
        verify: false, //审核
        goBack: false, //退回
        toPurchase: false, //转采购申请
      },

      //ag-grid 配置项 -
      gridOptions: null,
      columnDefs: null,
      rowData: [], //  表格数据
      dialogSelectRowIndex: "", //选中行
      loading: false, //加载条
      statusItem: [
        { code: 1, name: "待审" },
        { code: 2, name: "已审" },
        { code: 3, name: "退回" },
      ], //状态列表
    };
  },
  props: {
    addTab: {
      type: Function,
    },
  },
  beforeMount() {
   
  },
  created(){
     // 审核
    this.gridOptions = gridOptions();
    this.columnDefs = [
      {
        headerName: "申购单号",
        field: "purchaseNum",
        checkboxSelection: true,
        headerCheckboxSelection: true,
        headerCheckboxSelectionFilteredOnly: true,
         width: 160 
      },
      { headerName: "序号", field: "sequence", width: 70 },
      { headerName: "模具编号", field: "mouldNum",width: 90  },

      { headerName: "SAP名称", field: "sapName",width: 90 },
      { headerName: "零件类型", field: "partType", width: 90 },
      { headerName: "零件名称", field: "partName" , width: 90},

      { headerName: "材质", field: "matDescription", width: 68 },
      { headerName: "物料编码", field: "matNum", width: 95 },
      // { headerName: "硬度", field: "hardness", width: 68 },
      // { headerName: "是否倒角", field: "chamfer", width: 90 },
      { headerName: "长", field: "length", width: 52 },
      { headerName: "长度公差", field: "lengthTolerance", width: 90 },
      { headerName: "宽", field: "width", width: 52 },
      { headerName: "宽度公差", field: "widthTolerance", width: 90 },
      { headerName: "高", field: "heigth", width: 52 },
      { headerName: "高度公差", field: "heigthTolerance", width: 90 },
      { headerName: "数量", field: "amount", width: 68 },
      { headerName: "单重", field: "pieceWeight", width: 68 },
      { headerName: "总重", field: "grossWeight", width: 68 },
      { headerName: "设计", field: "designer", width: 68 },
      { headerName: "工厂代码", field: "factory", width: 90 },
      { headerName: "创建日期", field: "createDate" , width: 90},
      { headerName: "审核人", field: "auditor", width: 85 },
      { headerName: "审核时间", field: "auditDate", width: 90 },
      {
        headerName: "审核状态",
        field: "state",
         width: 90,
        valueFormatter: (params) => {
          for (let i = 0; i < this.statusItem.length; i++) {
            const status = this.statusItem[i];
            if (status.code === params.value) {
              return status.name;
            }
          }
          return params.value;
        },
      },
      {
        headerName: "采购申请类型",
        field: "purchaseRequestType",
         width: 115,
        cellRendererFramework: purchaseRequestTypeInput,
      },
      {
        headerName: "科目分配类别",
        field: "accountAssignmentCategory",
        width: 115,
        cellRendererFramework: accountAssignmentCategoryInput,
      },
      { headerName: "单位", field: "unit",width: 68, cellRendererFramework: unitInput },
      {
        headerName: "评估价格",
        field: "appraisalPrice",
        width: 90,
        cellRendererFramework: appraisalPriceInput,
      },
      {
        headerName: "价格单位",
        field: "priceUnit",
        width: 90,
        cellRendererFramework: priceUnitInput,
      },
      {
        headerName: "交货日期",
        field: "deliveryDate",
        width: 90,
        cellRendererFramework: deliveryDateInput,
      },
      {
        headerName: "物料组",
        field: "materialGroup",
        width: 80,
        cellRendererFramework: materialGroupInput,
      },
      {
        headerName: "库存地点",
        field: "stockLocation",
        width: 90,
        cellRendererFramework: stockLocationInput,
      },
      {
        headerName: "采购组",
        field: "purchaseGroup",
        width: 80,
        cellRendererFramework: purchaseGroupInput,
      },
      {
        headerName: "申请者",
        field: "applicant",
        width: 80,
        cellRendererFramework: applicantInput,
      },
      {
        headerName: "成本中心",
        field: "costCentre",
        width: 90,
        cellRendererFramework: costCentreInput,
      },
      {
        headerName: "项目文本",
        field: "itemText",
        width: 90,
        cellRendererFramework: itemTextInput,
      },
      {
        headerName: "项目类别",
        field: "projectType",
        width: 90,
        cellRendererFramework: projectTypeInput,
      }, //---
      {
        headerName: "采购组织",
        field: "purchaseOrg",
        width: 90,
        cellRendererFramework: purchaseOrgInput,
      }, //---
      {
        headerName: "供货工厂",
        field: "supplyFactory",
        width: 90,
        cellRendererFramework: supplyFactoryInput,
      },

      { headerName: "批次", width: 95,field: "batch", cellRendererFramework: batchInput },

      {
        headerName: "需求跟踪号",
        field: "requirementTrackNum",
        width: 110,
        cellRendererFramework: requirementTrackNumInput,
      },
    ];
 this.gridOptions.defaultColDef.autoHeight = true;
    this.gridOptions.defaultColDef.cellClass = "cell-wrap-text";

  },
  mounted() {
    // 请求权限
    authorize.getBtnAuth(this.pageCode, this.btnStatus).then((status) => {
      console.log(status, "按钮权限");
    });

   
    this.gridOptions.context = {
      componentParent: this,
    };
     this.searchForm.createDate = this.$utils.dateFormat('yyyy-MM-dd', new Date());   //设置默认日期今日
  this.getPurchaseRequest();
 },
  methods: {
    // 查询列表
    getPurchaseRequest() {
      let params = {
        size: this.searchForm.size,
        current: this.searchForm.current,
        eqParams: {
          state: 2,
        }, //精确查询
        likeParams: {
          factory: this.searchForm.factory,
          partType: this.searchForm.partType,
          createDate: this.searchForm.createDate,
          matDescription: this.searchForm.matDescription,
          mouldNum: this.searchForm.mouldNum,

          purchaseNum: this.searchForm.purchaseNum,
        }, //模糊查询
        orderBy: "createDate",
        isAsc: "false",
      };
      this.loading = true;
      _Api
        .getPurchaseRequestList(params)
        .then((response) => {
          let data = response.data;
          this.searchForm.total = data.total;
          if (data.code == 1 && data.total != 0) {
            this.rowData = data.rows;
            this.loading = false;
          } else {
            this.loading = false;
            this.rowData = [];
          }
        })
        .catch((err) => {
          this.rowData = [];
          this.loading = false;
          this.$alert(err.data.message, {
            showClose: false,
            confirmButton: "确定",
            customClass: "alertFailure",
          });
        });
    },
    // 表格聚焦行
    dialogRowFocus(event) {
      console.log(event,888);
      this.dialogSelectRowIndex = event.rowIndex;
      console.log(this,77);
    },
    handleClickCell(event){
               console.log(event,9999);
    },
    // 转采购申请
    purchaseApplay() {
      let rows = this.gridOptions.api.getSelectedRows();
     
      if (rows.length <= 0) {
        this.$alert("提示：请选择需要转采购申请的数据", {
          showClose: false,
          confirmButtonText: "确定",
          customClass: "alertPrompt",
        });
        return;
      }
      let updateRows = [];
      rows.forEach((item) => {
        if (item.unit.length == 0) {
          item.unit = "KG";
        }
        if (!item.unit) {
          this.$alert("提示：单位不能为空", {
            showClose: false,
            confirmButtonText: "确定",
            customClass: "alertPrompt",
          });
          return;
        }else if (!item.appraisalPrice) {
          this.$alert("提示：评估价格不能为空", {
            showClose: false,
            confirmButtonText: "确定",
            customClass: "alertPrompt",
          });
          return;
        } else if (item.deliveryDate == null) {
          this.$alert("提示：交货日期不能为空", {
            showClose: false,
            confirmButtonText: "确定",
            customClass: "alertPrompt",
          });
          return;
        } else if (!item.purchaseGroup) {
          this.$alert("提示：采购组不能为空", {
            showClose: false,
            confirmButtonText: "确定",
            customClass: "alertPrompt",
          });
          return;
        } else if (!item.applicant) {
          this.$alert("提示：申请者不能为空", {
            showClose: false,
            confirmButtonText: "确定",
            customClass: "alertPrompt",
          });
          return;
        }  else {
          if (item.purchaseGroup == "E26" || item.purchaseGroup == "E27") {
            if (!item.supplyFactory) {
              this.$alert("提示：供货工厂不能为空", {
                showClose: false,
                confirmButtonText: "确定",
                customClass: "alertPrompt",
              });
              return;
            } else if (!item.purchaseOrg) {
              this.$alert("提示：采购组织不能为空", {
                showClose: false,
                confirmButtonText: "确定",
                customClass: "alertPrompt",
              });
              return;
            } else {
              let obj = {};
              obj = item;
              obj.state = 4;
              if (item.purchaseRequestType.length == 0) {
                obj.purchaseRequestType = "NB";
              } else {
                obj.purchaseRequestType = item.purchaseRequestType;
              }
              if (item.unit.length == 0) {
                obj.unit = "KG";
              } else {
                obj.unit = item.unit;
              }
              obj.modifyer = constant.user.loginName; //登录人名称
              obj.modifyerId = constant.user.id; //登录人Id
              obj.modifyDate = this.curentTime(); //获取当前时间

              updateRows.push(obj);
            }
          } else {
            let obj = {};
            obj = item;
            obj.state = 4;
            if (item.purchaseRequestType.length == 0) {
              obj.purchaseRequestType = "NB";
            } else {
              obj.purchaseRequestType = item.purchaseRequestType;
            }
            if (item.unit.length == 0) {
              obj.unit = "KG";
            } else {
              obj.unit = item.unit;
            }
            obj.modifyer = constant.user.loginName; //登录人名称
            obj.modifyerId = constant.user.id; //登录人Id
            obj.modifyDate = this.curentTime(); //获取当前时间

            updateRows.push(obj);
          }
        }
      });

      if (updateRows.length == rows.length) {
        updateRows.forEach((item) => {
          if (item.purchaseGroup == "E26" || item.purchaseGroup == "E27") {
            if (!item.supplyFactory) {
              this.$alert("提示：供货工厂不能为空", {
                showClose: false,
                confirmButtonText: "确定",
                customClass: "alertPrompt",
              });
              return;
            } else if (!item.purchaseOrg) {
              this.$alert("提示：采购组织不能为空", {
                showClose: false,
                confirmButtonText: "确定",
                customClass: "alertPrompt",
              });
              return;
            } else {
            }
          }
        });

        _Api
          .submiteviewer(updateRows)
          .then((response) => {
            let data = response.data;
            if (data.code == 1) {
              this.$message({
                message: data.msg,
                type: "success",
              });

              this.getPurchaseRequest();
              // this.addTab({
              //   cName: "采购申请列表",
              //   name: "purchasesApplyList",
              //   completed: false,
              // });
            } else {
              this.$message({
                message: data.msg,
                type: "warning",
              });
            }
          })
          .catch((err) => {
            this.$alert(err.data.message, {
              showClose: false,
              confirmButton: "确定",
              customClass: "alertFailure",
            });
          });
      }
    },
    // 获取当前日期时间
    curentTime() {
      var now = new Date();

      var year = now.getFullYear(); //年
      var month = now.getMonth() + 1; //月
      var day = now.getDate(); //日

      var hh = now.getHours(); //时
      var mm = now.getMinutes(); //分
      var ss = now.getSeconds(); //分

      var clock = year + "-";

      if (month < 10) clock += "0";

      clock += month + "-";

      if (day < 10) clock += "0";

      clock += day + " ";

      if (hh < 10) clock += "0";

      clock += hh + ":";
      if (mm < 10) clock += "0";
      clock += mm + ":";

      if (ss < 10) clock += "0";
      clock += ss;
      return clock;
    },
    // 限定短日期，形如 (2008-07-22)
    strDateTime(str) {
      var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
      if (r == null) return false;
      var d = new Date(r[1], r[3] - 1, r[4]);
      return (
        d.getFullYear() == r[1] &&
        d.getMonth() + 1 == r[3] &&
        d.getDate() == r[4]
      );
    },
    // 每页显示条数改变回调
    handleSizeChange(val) {
      this.searchForm.size = val;
      this.getPurchaseRequest();
    },
    // 页码改变回调
    handleCurrentChange(val) {
      this.searchForm.current = val;
      this.getPurchaseRequest();
    },
    // 点击上一页回调
    handlePrevClick(val) {
      this.searchForm.current = val;
    },
    // 点击下一页回调
    handleNextClick(val) {
      this.searchForm.current = val;
    },
  },
};
</script>
<style lang="less">
.cell-wrap-text {
  white-space: normal !important;
}

</style>